var express = require("express");
var router = express.Router();
let {collectionModel} = require("../models/collectionModel") //导入模型


/* GET users listing. */

//获取题目
router.get("/GetCollection", async (req, res, next)=> {
    let result = await collectionModel.find().populate('exerciseId').populate('studentId')
    if (result) {
      res.send({
        code: 200,
        obj: result,
      });
    }
  
});

//新增收藏题
router.post("/CreatCollection", async (req, res, next)=> {
  console.log(req.body)
  let result = await collectionModel.create(req.body)
  if (result) {
    res.send({
      code: 200,
      message:"收藏成功",
      obj: result,
    });
  }
});

//删除收藏题
router.post("/DeleteCollection", async (req, res, next)=> {
    console.log(req.body)
    let result = await collectionModel.deleteOne(req.body)
    if (result) {
      res.send({
        code: 200,
        message:"删除成功",
        obj: result,
      });
    }
  });

module.exports = router;
